//
//  WLLStatusModel.swift
//  WLLWeibo
//
//  Created by 王乐乐 on 16/8/13.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class WLLStatusModel: NSObject {
    // MARK: - 模型属性
    /// 创建时间
    var created_at: String?
    /// 微博ID
    var id: Int64 = 0
    /// 微博信息内容
    var text: String?
    /// 微博来源
    var source: String?
    ///  用户模型
    var user: WLLUserModel?
    /// 转发微博
    var retweeted_status:WLLStatusModel?
    /// 配图
    var pic_urls: [WLLPictureInfo]?
    /// int	转发数
    var reposts_count: Int = 0
    /// int	评论数
    var comments_count: Int = 0
    ///int	表态数
    var attitudes_count: Int = 0
    
    init(dict:[String : AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
            // 判断value 是否为nil 且是否可以转成一个字典
            guard let v = value as?[String:AnyObject] else{
                return
            }
            //手动给user 赋值
            user = WLLUserModel(dict: v)
            
        }else if key == "retweeted_status"{
            // 判断value 是否为nil 且是否可以转成一个字典
            guard let v = value as?[String:AnyObject] else{
                return
            }
            //手动赋值
            retweeted_status = WLLStatusModel(dict: v)
            
        }else if key == "pic_urls"{
            // 判断 value 是否为 nil 且是否可以转成一个字典
            guard let v = value as?[[String:AnyObject]] else{
                return
            }
            //手动赋值
            //创建临时可变数组
            var tmpArray :[WLLPictureInfo] = [WLLPictureInfo]()
            
            for dic in v {
                let pic = WLLPictureInfo(dict: dic)
                tmpArray.append(pic)
            }
            //赋值
            pic_urls = tmpArray
            
        } else{
            super.setValue(value, forKey: key)
        }
    }
    
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
}
